package com.xyy.saas.payment.service.impl;

import com.xyy.saas.payment.dao.mapper.RefundReturnAdvanceMapper;
import com.xyy.saas.payment.dao.model.RefundReturnAdvance;
import com.xyy.saas.payment.service.RefundReturnAdvanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class RefundReturnAdvanceServiceImpl implements RefundReturnAdvanceService {
    @Autowired
    private RefundReturnAdvanceMapper refundReturnAdvanceMapper;

    /**
     * 插入
     *
     * @param refundReturnAdvance
     * @return
     */
    @Override
    public boolean insert(RefundReturnAdvance refundReturnAdvance) {
        return refundReturnAdvanceMapper.insert(refundReturnAdvance) > 0;
    }

    /**
     * 插入或更新
     *
     * @param refundReturnAdvance
     * @return
     */
    @Override
    public boolean insertOrUpdate(RefundReturnAdvance refundReturnAdvance) {
        if(refundReturnAdvance.getId() != null) {
            return updateStatusById(refundReturnAdvance);
        }
        else {
            return insert(refundReturnAdvance);
        }
    }

    /**
     * 根据退款流水号查询
     *
     * @param refundNo
     * @return
     */
    @Override
    public RefundReturnAdvance selectByRefundNo(String refundNo) {
        return refundReturnAdvanceMapper.selectByRefundNo(refundNo);
    }

    /**
     * 根据ID更新状态
     *
     * @param refundReturnAdvance
     * @return
     */
    @Override
    public boolean updateStatusById(RefundReturnAdvance refundReturnAdvance) {
        return refundReturnAdvanceMapper.updateStatusById(refundReturnAdvance) > 0;
    }
}
